package com.example.srb.core.controller.admin;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.srb.common.result.Result;
import com.example.srb.core.pojo.entity.UserInfo;
import com.example.srb.core.pojo.query.UserInfoQuery;
import com.example.srb.core.service.UserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户基本信息 前端控制器
 * </p>
 *
 * @author Helen
 * @since 2021-02-20
 */
@Api(tags = "会员接口")
@RestController
@RequestMapping("/admin/core/userInfo")
@Slf4j
//@CrossOrigin
public class AdminUserInfoController {

    @Autowired
    private UserInfoService userInfoService;

    @ApiOperation("获取会员分页列表")
    @GetMapping("/list/{pageNum}/{pageSize}")
    public Result listPage(@PathVariable @ApiParam(value = "当前页码",required = true) Long pageNum,
                           @PathVariable @ApiParam(value = "每页展示记录数",required = true) Long pageSize,
                           @ApiParam(value = "查询对象",required = false) UserInfoQuery userInfoQuery){

        Page<UserInfo> pageParam = new Page<>(pageNum,pageSize);
        IPage<UserInfo> pageModel = userInfoService.listPage(pageParam,userInfoQuery);
        return Result.ok().data("pageModel",pageModel);

    }

    @ApiOperation("锁定和解锁用户状态")
    @PutMapping("/lock/{id}/{status}")
    public Result lock(@ApiParam(value = "用户主键id",required = true)@PathVariable Long id,
                       @ApiParam(value = "锁定状态（0：锁定 1：正常）",required = true)@PathVariable Integer status){

        userInfoService.lock(id,status);
        return Result.ok().message(status==0 ? "锁定成功" : "解锁成功");
    }


}

